<template>
  <div id="moreEdit">
        <h1>基本信息情况</h1>
        <el-form :model="deptMoreeditForm" label-width="150px" :rules="deptMoreEditFormRules" ref="deptMoreeditForm" :inline="true" style="width:1000px">
          <el-form-item label="单位全称" prop="Name" style="width:570px;">
            <b>{{deptMoreeditForm.Name}}</b>
          </el-form-item>
          <div id="depteditswitch"><el-switch v-model="depteditVisible" active-color="#13ce66" inactive-color="#ff4949" :change="depteditsBtnsShow()"></el-switch> <span>编辑</span></div>
          <div class="depteditBtns" v-show="depteditBtnsVisible" ref="TreeBtns">
            <div style="clear:both"></div>
            <el-button type="primary" @click.native="deptMoreEdit"  style="margin-left:150px;">修改</el-button>
          </div>
        </el-form>
  </div>
</template>

<script>
export default {
  watch: {
    '$route': 'getDeptMoreDetail'
  },
  name: 'HelloWorld',
  data () {
    return {
      moreDetailLoading: false,
      depteditVisible: false,
      depteditBtnsVisible: false,
      deptMoreeditForm: {},
      deptMoreEditFormRules: {
      },
      editLoading: false,
      deptMoreEditFormLoading: false,
      hyoptions: [{
        value: '类别1',
        label: '类别1'
      }, {
        value: '类别2',
        label: '类别2'
      }],
      sydwoptions: [{
        value: '类型1',
        label: '类型1'
      }, {
        value: '类型2',
        label: '类型2'
      }]
    }
  },
  methods: {
    depteditsBtnsShow () {
      console.log(this.treeVisible)
      this.depteditBtnsVisible = this.depteditVisible
    },
    deptMoreEdit: function () {
      console.log('监听' + this.$route.params.id)
      this.$router.push({path: `/dept/moreEdit0/${this.$route.params.id}`})
    },
    // 修改提交
    deptMoreeditSubmit: function () {
      var _this = this
      this.$refs.deptMoreeditForm.validate((valid) => {
        if (valid) {
          _this.deptMoreEditFormLoading = true
          let para = {
            id: this.$route.params.id,
            Name: this.deptMoreeditForm.Name,
            Jigouguige: this.deptMoreeditForm.Jigouguige,
            Qitaquancheng: this.deptMoreeditForm.Qitaquancheng,
            Hangyeleibie: this.deptMoreeditForm.Hangyeleibie,
            Jingneijingwai: this.deptMoreeditForm.Jingneijingwai,
            Shiyedanweileixing: this.deptMoreeditForm.Shiyedanweileixing,
            Xinyongdaima: this.deptMoreeditForm.Xinyongdaima,
            Pizhunwenhao: this.deptMoreeditForm.Pizhunwenhao,
            Farenzhengshuhao: this.deptMoreeditForm.Farenzhengshuhao,
            CanjiagoShelishijiangzuoshijian: this.deptMoreeditForm.Shelishijian,
            Zuzhijigoudaima: this.deptMoreeditForm.Zuzhijigoudaima,
            Fadingdaibiaoren: this.deptMoreeditForm.Fadingdaibiaoren,
            CanGong: this.deptMoreeditForm.CanGong,
            Youbian: this.deptMoreeditForm.Youbian,
            Gudingdianhua: this.deptMoreeditForm.Gudingdianhua,
            Tongxindizhi: this.deptMoreeditForm.Tongxindizhi
          }
          this.$http.post(`/dept/edit`, para).then(function (response) {
            console.log(response.data.IsSuccess)
            if (response.data.IsSuccess === true) {
              _this.deptMoreEditFormLoading = false
              _this.$message({
                message: '提交成功',
                type: 'success'
              })
            } else {
              console.log('提交失败:' + response.data.Msg)
              _this.$message({
                message: '提交失败:' + response.data.Msg,
                type: 'error'
              })
            }
            _this.deptMoreEditFormLoading = false
          }).catch(function (error) {
            console.log(error)
            _this.$message({
              message: '获取失败:' + error,
              type: 'error'
            })
          })
        }
      })
    },
    getDeptMoreDetail () {
      let para = {
        id: this.$route.params.id
      }
      var _this = this
      this.moreDetailLoading = true
      this.$http
        .post(`/dept/moreDetails`, para)
        .then(function (response) {
          console.log(para)
          _this.moreDetailLoading = false
          if (response.data.IsSuccess === true) {
            console.log('获取成功')
            console.log('test111:' + response.data.Result.depttype)
            if (response.data.Result.depttype === '分类') {
              _this.$router.push({path: `/dept/moreDetail0/${_this.$route.params.id}`})
            }
            if (response.data.Result.depttype === '单位') {
              _this.$router.push({path: `/dept/moreDetail/${_this.$route.params.id}`})
            }
            if (response.data.Result.depttype === '部门') {
              _this.$router.push({path: `/dept/moreDetail2/${_this.$route.params.id}`})
            }
            _this.deptMoreeditForm = response.data.Result
          } else {
            console.log('获取失败:' + response.data.Msg)
            _this.$message({
              message: '获取失败:' + response.data.Msg,
              type: 'error'
            })
          }
        })
        .catch(function (error) {
          console.log(error)
          _this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    }
  },
  mounted () {
    this.getDeptMoreDetail()
  }
}
</script>
